package com.example.newinfinity.UserRoom

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

@Dao
interface UserDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)  //插入用户重复时，覆盖之前的用户数据
    suspend fun insertUser(user: User)

    @Update
    suspend fun updateUser(user: User)

    //找到当前登录用户
    @Query("SELECT * FROM user_table WHERE isLogin = 1")
    suspend fun getLoginInUser(): User?

    //寻找当前用户输入信息的用户判断存在
    @Query("SELECT * FROM user_table WHERE userName = :name AND userPassword = :password LIMIT 1")
    suspend fun getUserByName(name: String, password: String): User?

    //获取所有注册过的用户
    @Query("SELECT * FROM user_table")
    fun getAllUsers(): LiveData<List<User>>?

}